package com.yipei.business.controller;

import com.yipei.business.domain.MlFinancialProducts;
import com.yipei.business.service.IMlFinancialProductsService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 理财产品Controller
 *
 * @author yipei
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/business/products")
@Api(tags = "理财产品", description = "理财产品管理")
public class MlFinancialProductsController extends BaseController {
    @Autowired
    private IMlFinancialProductsService mlFinancialProductsService;

    /**
     * 查询理财产品列表
     */
    //@PreAuthorize("@ss.hasPermi('business:products:list')")
    @ApiOperation("理财产品获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlFinancialProducts mlFinancialProducts) {
        startPage();
        List<MlFinancialProducts> list = mlFinancialProductsService.selectMlFinancialProductsList(mlFinancialProducts);
        return getDataTable(list);
    }

    /**
     * 导出理财产品列表
     */
    //@PreAuthorize("@ss.hasPermi('business:products:export')")
    @ApiOperation("理财产品导出数据")
    @Log(title = "理财产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlFinancialProducts mlFinancialProducts) {
        List<MlFinancialProducts> list = mlFinancialProductsService.selectMlFinancialProductsList(mlFinancialProducts);
        ExcelUtil<MlFinancialProducts> util = new ExcelUtil<MlFinancialProducts>(MlFinancialProducts.class);
        util.exportExcel(response, list, "理财产品数据");
    }

    /**
     * 获取理财产品详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:products:query')")
    @ApiOperation("理财产品通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlFinancialProductsService.selectMlFinancialProductsById(id));
    }

    /**
     * 新增理财产品
     */
    //@PreAuthorize("@ss.hasPermi('business:products:add')")
    @ApiOperation("理财产品新增数据")
    @Log(title = "理财产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlFinancialProducts mlFinancialProducts) {
        return toAjax(mlFinancialProductsService.insertMlFinancialProducts(mlFinancialProducts));
    }

    /**
     * 修改理财产品
     */
    //@PreAuthorize("@ss.hasPermi('business:products:edit')")
    @ApiOperation("理财产品修改数据")
    @Log(title = "理财产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlFinancialProducts mlFinancialProducts) {
        return toAjax(mlFinancialProductsService.updateMlFinancialProducts(mlFinancialProducts));
    }

    /**
     * 删除理财产品
     */
    //@PreAuthorize("@ss.hasPermi('business:products:remove')")
    @ApiOperation("理财产品删除数据")
    @Log(title = "理财产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlFinancialProductsService.deleteMlFinancialProductsByIds(ids));
    }
}
